package com.ngmaster.socket.callback;

import com.alibaba.fastjson.JSON;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

/**
 * 默认心跳回调
 * */
public class CallbackDefault implements Callback {

    private static Logger logger = LoggerFactory.getLogger(CallbackDefault.class);

    @Override
    public void onFailure(Call call, IOException e) {
        logger.error("[req:" + call.request().body().toString() + "]", e);
    }

    @Override
    public void onResponse(Call call, Response response) throws IOException {
        logger.info("[reqLength:{}, reqMetaType:{}, callback:{}]", new Object[] {
                call.request().body().contentLength(), call.request().body().contentType(), response.body().string()
        });
        response.close();
    }
}
